package com.nytd.demo.controller;

import com.nytd.demo.pojo.request.AddBlogRequest;
import com.nytd.demo.pojo.request.UpdateBlogRequest;
import com.nytd.demo.pojo.response.BlogDetailResponse;
import com.nytd.demo.pojo.response.BlogResponse;
import com.nytd.demo.pojo.response.Result;
import com.nytd.demo.service.BlogInfoService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/blog")
public class BlogInfoController {
    @Resource(name = "blogInfoService")
    private BlogInfoService blogInfoService;

    @GetMapping("/getList")
    public List<BlogResponse> getList() {
        return blogInfoService.getList();
    }
    @GetMapping("/getBlogDetail")
    public BlogDetailResponse getBlogDetail(@NotNull Integer blogId) {
        log.info("blogId: {}", blogId);
        return blogInfoService.getBlogDetail(blogId);
    }
    @PostMapping("/add")
    public Result<Boolean> addBlog(@Validated @RequestBody AddBlogRequest addBlogRequest) {
        log.info("addBlog接收参数: {}", addBlogRequest);
        return Result.success(blogInfoService.addBlog(addBlogRequest));
    }
    @PostMapping("/update")
    public Result<Boolean> updateBlog(@Validated @RequestBody UpdateBlogRequest updateBlogRequest) {
        log.info("updateBlogRequest接收参数: {}", updateBlogRequest);
        return Result.success(blogInfoService.update(updateBlogRequest));
    }
    @PostMapping("/delete")
    public Result<Boolean> deleteBlog(@NotNull Integer blogId) {
        log.info("blogId: {}", blogId);
        return Result.success(blogInfoService.delete(blogId));
    }

}
